<template>
    <div>
        <el-container>
            <el-main>
                <el-container class="parent-body">
                    <el-header class="content-header">
                        订单设置
                    </el-header>
                    <el-main class="info-main">
                        <el-row>
                            <el-col style="height: 100%;width:620px;" :span="8" :offset="6">
                                <el-form ref="form" :rules="rules" :model="form" label-width="150px">
                                    <el-form-item label="秒杀订单超过：" prop="secondKillOrderExceeded">
                                        <el-input class="input-width" v-model="form.seckillTimeout"><template slot="append">分</template></el-input>
                                        未付款，订单自动关闭
                                    </el-form-item>
                                    <el-form-item label="正常订单超过：" prop="normalOrderExceeding">
                                        <el-input class="input-width" v-model="form.orderTimeout"><template slot="append">分</template></el-input>
                                        未付款，订单自动关闭
                                    </el-form-item>
                                    <el-form-item label="自动收货设置：" prop="deliveryMoreThan">
                                        <el-input class="input-width" v-model="form.takeTimeout"><template slot="append">天</template></el-input>
                                        未收货，订单自动完成
                                    </el-form-item>
                                    <el-form-item label="售后期限设置：" prop="orderFulfillmentExceeds01">
                                        <el-input class="input-width" v-model="form.serviceTimeout"><template slot="append">天</template></el-input>
                                        自动结束交易，不能申请售后
                                    </el-form-item>
                                    <el-form-item label="订单完成超过：" prop="orderFulfillmentExceeds02">
                                        <el-input class="input-width" v-model="form.commentTimeout"><template slot="append">天</template></el-input>
                                        自动五星好评
                                    </el-form-item>
                                    <el-form-item>
                                        <el-button type="primary" @click="submitForm(form)">提交</el-button>
                                    </el-form-item>
                                </el-form>
                            </el-col>
                        </el-row>
                    </el-main>
                </el-container>
            </el-main>
        </el-container>
    </div>
</template>

<script>

import orderConfigApi from "@/api/order/orderConfig"
    export default {
        data() {
            return {
                form:{
                     id:'1',
                   orderTimeout:'',
                   seckillTimeout:'',
                   takeTimeout:'',
                   serviceTimeout:'',
                    commentTimeout:''
                },
                rules: {
                    seckillTimeout: [
                        {required: true, message: '请输入秒杀订单超过', trigger: 'blur'}
                    ],
                   orderTimeout: [
                        {required: true, message: '请输入正常订单超过', trigger: 'blur'}
                    ],
                    takeTimeout: [
                        {required: true, message: '请输入自动收货时间', trigger: 'blur'}
                    ],
                    serviceTimeout: [
                        {required: true, message: '请输入订单完成售后期限', trigger: 'blur'}
                    ],
                    commentTimeout: [
                        {required: true, message: '请输入订单完成超过', trigger: 'blur'}
                    ],
                }
            }
        },
        methods:{
            submitForm(formName) {
               this.commitData(formName);
            },
// 查询出来的数据
            indata(){
orderConfigApi.getById().then(reponse=>{

    console.log(reponse);


                    this.form.orderTimeout=reponse.data.data.orderTimeout;
                    this.form.seckillTimeout=reponse.data.data.seckillTimeout;
                    this.form.takeTimeout=reponse.data.data.takeTimeout;
                    this.form.serviceTimeout=reponse.data.data.serviceTimeout;
                    this.form.commentTimeout=reponse.data.data.commentTimeout;

})
            },

            commitData(form){
orderConfigApi. updateById(form).then(response=>{

    this.$message(response.data.message);
    this.indata();
})

            }


        },

        mounted(){

            this.indata();
        }
    }
</script>

<style scoped>
    .parent-body{
        border:1px solid #E4E4E4;
    }
    .content-header{
        height:50px;
        line-height: 50px;
        background-color:#F3F3F3;
        color:#666666;
    }
    .info-main{
        background-color:#fff;
    }
    .input-width{
        width:250px;
    }
</style>